/**
 * @Author ZhaoLei
 * @FileName HuiDaoAPI.js
 * @Description  会道接口查询
 * @Date 2022-10-28 9:38
 * @Copyright By hftsoft
 */

import { Toast } from 'vant';
import api from '@/utils/http/impl/axios_api_instance';

const apiHost = process.env.API_HUIDAO_HOST

const postNew = (url, data) => api.postNew(url, data).then(response => response.data || {});

/**
 * 请求基础方法
 * @param url
 * @param data
 * @return {Promise<AxiosResponse<any>>}
 */
const baseHuiDaoAPIPost = (url, data = {}) => {
  return postNew(`${apiHost}${url}`, data).then(res => {
    let { status, result, message } = res;

    if (status === 200) return Promise.resolve(result);

    Toast(message || '请求失败');
  });
};

/**
 * 查询会道课程列表
 * @return {Promise<AxiosResponse<any>>}
 */
const getHuiDaoItemList = () => baseHuiDaoAPIPost('/hstalk/talk/getHuidaoItemList');

const getHuiDaoPageList = (id) => baseHuiDaoAPIPost('/hstalk/talk/pageList', {
  condition: {
    itemId: id
  },
  pageIndex: 1,
  pageSize: 3
})

export default {
  getHuiDaoItemList,
  getHuiDaoPageList
};
